package gob.inei.enaho.model.service;

import java.sql.SQLException;

import util.android.sqlite.CommandSQLite;
import util.android.sqlite.SQLiteUtil;
import android.database.Cursor;
import gob.inei.enaho.model.domain.ubicacion.CentroPoblado;
import gob.inei.enaho.model.domain.ubicacion.ViviendaMarco;



public class ViviendaMarcoService 
extends AbstractService
{

	@Override
	public String getNombreTabla() {
		return "Campo_Vivienda_Marco";
	}
	
	public ViviendaMarco findById(String conglomerado, String vivienda) throws SQLException {
		String sql = "select * from Campo_Vivienda_Marco " +
				"where conglome='"+conglomerado+"' and vivienda='"+vivienda+"'";
				
		
		return (ViviendaMarco) SQLiteUtil.executeQueryUnaVez(getOpenHelper(), sql, new CommandSQLite() {			
			@Override
			public Object execute(Cursor cr) throws SQLException {
				
				ViviendaMarco obj = new ViviendaMarco();
				CentroPoblado ccpp = new CentroPoblado(); 
				ccpp.setCodigo(SQLiteUtil.getString(cr,"CodCCPP"));				
				ccpp.setNombre(SQLiteUtil.getString(cr,"NomCCPP"));				
				obj.setCentroPoblado(ccpp);							
				obj.setCorrelativo(SQLiteUtil.getInteger(cr,"NroVivienda"));
				obj.setTipoVivienda(SQLiteUtil.getString(cr,"TipoVivienda"));
				
				obj.setManzanaMuestral(SQLiteUtil.getString(cr,"Manzana"));
				obj.setCategoriaVia(SQLiteUtil.getString(cr,"CatVia"));
				obj.setNombreVia(SQLiteUtil.getString(cr,"NombreVia"));
				obj.setCategoriaVia(SQLiteUtil.getString(cr,"CatVia"));				
				obj.setPuerta(SQLiteUtil.getString(cr,"Puerta"));
				obj.setInterior(SQLiteUtil.getString(cr,"Interior"));
				obj.setPiso(SQLiteUtil.getString(cr,"Piso"));
				obj.setManzana(SQLiteUtil.getString(cr,"Mz"));
				obj.setLote(SQLiteUtil.getString(cr,"Lote"));
				obj.setKilometro(SQLiteUtil.getString(cr,"Km"));
				obj.setBlock(SQLiteUtil.getString(cr,"NroBlock"));				
				return obj;
			}
		});
	}

	
	
	
	
}
